% BEM-LAP-MAT project
% Matlab/Freemat codes
% Copyright 2008 Stephen Kirkup 
% http://www.researchgate.net/profile/Stephen_Kirkup
% University of Central Lancashire
% Issued under the GNU General Public License 2007, see gpl.txt
% www.boundary-element-method.com
% contact: stephen@boundary-element-method.com
% http://www.researchgate.net/profile/Stephen_Kirkup

% function [L,M,Mt,N] = lbem2(m,p,vecp,n,vertpts,elemvert,p_on,needL,needM,needMt,needN)
% Sets up the matrices required in the boundary element method
%  for m (observation) points p with a vector (derivative) direction of
%  vecp at the points p. The boundary is made up of n elements; vertpts lists the coordinates
%  of the edges of the elements and elemvert lists the pairs of vertices
%  that define each element. p_on idicates whether the point p(i) lies on the ith panel.
%  needL,needM,needMt,needN indicate which matrices are needed by being set to true.


function [L,M,Mt,N] =lbem2(m,p,vecp,n,vertpts,elemvert,p_on,needL,needM,needMt,needN)
  
  [qa,qb]=vertices(n,vertpts,elemvert);

  for (i=1:m)
    for (j=1:n)
    [L(i,j),M(i,j),Mt(i,j),N(i,j)]=l2lc(p(i,:),vecp(i,:),qa(j,:),qb(j,:),p_on&i==j,needL,needM,needMt,needN);
    end
  end
